// 19.删除链表的倒数第N个结点
package LeetcodeHot100;


public class Solution019 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode temp = head;
        int length = 0;
        while (temp != null) {
            temp = temp.next;
            length++;
        }
        int beforeDelete = length - n - 1;
        if (beforeDelete == -1)
            return head.next;
        temp = head;
        while (beforeDelete-- != 0) {
            temp = temp.next;
        }
        temp.next = temp.next.next;
        return head;
    }
}
